<cfinclude template="/ecada/header.cfm">
<cfoutput>

	<!--- display all completed experiments --->
	
	<h2>Completed experiments</h2>
	
	<cfquery name = "offline" datasource = "exp" result="test">
		SELECT * 
		FROM experiment
		WHERe StatusID = (SELECT id
							FROM expstatus
							WHERE Status = 'Completed')
		AND (userid = #session.id#
			OR GroupID IN 
						(
							SELECT gu.GroupID
							FROM groupusers gu
							WHERE gu.UserID = #session.id#
						)
			)
		ORDER BY experiment.id
	</cfquery>
	<cfoutput>
	Query Time: #test.executiontime#<br><br>
</cfoutput>
	<cfif offline.recordcount eq 0>
		There are no completed experiemnts
	<cfelse>
		<cfloop query = "offline">
			<table border="1">
				<cfquery datasource="exp" name="numparticipants">
						SELECT count(distinct participantid) as cnt
						FROM givesanswer,trial
						WHERE expid=#offline.id# 
						AND trial.id = givesanswer.trialid 
				</cfquery>
				<tr>
					<th colspan=2>Experiment Details</th>
				</tr>
				<tr>
					<td colspan=2>#offline.title#</td>
				</tr>
				<tr>
					<td colspan=2><p style="width: 400px;">#offline.description#</p></td>
				</tr>
				<tr>
					<td >Maximum Participants </td>
					<td>#offline.maxpart#</td>
				</tr>
				<tr>
					<td>Number of Participants</td>
					<td> #numparticipants.cnt#</td>
				</tr>
				<tr>
					<td>Start date: </td>
					<td>#offline.startDate#</td>
				</tr>
				<tr>
					<td>End date:</td>
					<td>#offline.endDate#</td>
				</tr>
				<tr>
					<td>Click to see more detail </td>
					<td>
						<a href="/ecada/viewexp/expdetail.cfm?id=#offline.id#">Detail</a>
					</td>
				</tr>
				<tr>
					<td>
						 Click to edit this experiment.
					</td>
					<td>
						<form method="post" action="./../EE.cfm?currid=#id#">
							<input type = "hidden" name = "#id#" value="#id#">
							<input type = "submit" value="Edit Experiment" style="background-color:green;color:black;">
						</form>
					</td>
				</tr>
				<tr>
					<td>
						Click to resume this experiment.
					</td>
					<td>
						<form method="post" action="experimentClose.cfm">
							<input type = "hidden" name = "id" value="#id#">
							<input type="hidden" value="0" name="close">
							<input type = "submit" value="Resume experiment" style="background-color:red; color:white;">
						</form>
					</td>
				</tr>
				<tr>
					<td>
						Click to reset the experiment.
					</td>
					<td>
						<form method="post" action="##">
							<input type = "hidden" name = "id" value="#id#">
							<input type="hidden" value="0" name="close">
							<input type = "submit" value="Reset experiment">
						</form>
					</td>
				</tr>
				<tr>
					<td>
						Click to see non-anonymous paticipants.
					</td>
					<td>
						<form method="post" action="##">
							<input type = "hidden" name = "id" value="#id#">
							<input type="hidden" value="0" name="close">
							<input type = "submit" value="Participants">
						</form>
					</td>
				</tr>
			</table>
			<br>
			<br>
		</cfloop>
		
	</cfif>

</cfoutput>
<cfinclude template="/ecada/footer.cfm">
